//
//  TestListViewController.m
//  SmartWatch
//
//  Created by zwj on 2022/11/24.
//

@interface TestTableCell : UITableViewCell

@property(nonatomic,strong) MyLinearLayout *root;
@end

@implementation TestTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if(self == [super initWithStyle: style reuseIdentifier:reuseIdentifier]){
        self.backgroundColor = COLOR_5;
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        
        MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        root.myWidth = kScreenWidth;
        root.paddingTop = 15;
        root.cacheEstimatedRect = YES;
        root.heightSize.equalTo(root.heightSize).min(70);
        [self.contentView addSubview:root];
        self.root = root;
        
        MyLinearLayout *backView = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        backView.backgroundColor = COLOR_4;
        ViewCorner(backView, 15);
        backView.myHorzMargin = 15;
        backView.myHeight = kAutoHeight;
        backView.padding = UIEdgeInsetsMake(10, 10, 10, 10);
        backView.subviewVSpace = 10;
        [root addSubview:backView];

        MyLinearLayout *top = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
        top.myHorzMargin = 1;
        top.myHeight = kAutoHeight;
        top.gravity = MyGravity_Vert_Center;
        top.subviewHSpace = 5;
        [backView addSubview:top];

        {
            UILabel *name = [UILabel createLabelText:@"周晓咏" font:UIFontBoldMake(14) textColor:COLOR1515];
            name.mySize = kAutoSize;
            [top addSubview:name];
            
            UIImageView *sex = [[UIImageView alloc]initWithImage:UIImageMake(@"profile_nv")];
            sex.mySize = CGSizeMake(16, 16);
            [top addSubview:sex];
            
        }
        
        UILabel *height = UILabel.new;
        height.mySize = kAutoSize;
        height.attributedText = AttributedString(@"• 出生日期：", UIFontMake(14), COLOR999, @"1985-09-20", UIFontMake(14), COLOR1515, NSTextAlignmentLeft, 3);
        [backView addSubview:height];
        
        UILabel *Height = UILabel.new;
        Height.mySize = kAutoSize;
        Height.attributedText = AttributedString(@"• 身高：", UIFontMake(14), COLOR999, @"150cm", UIFontMake(14), COLOR1515, NSTextAlignmentLeft, 3);
        [backView addSubview:Height];
        
        UILabel *weight = UILabel.new;
        weight.mySize = kAutoSize;
        weight.attributedText = AttributedString(@"• 体重：", UIFontMake(14), COLOR999, @"55kg", UIFontMake(14), COLOR1515, NSTextAlignmentLeft, 3);
        [backView addSubview:weight];
        
        UILabel *phone = UILabel.new;
        phone.mySize = kAutoSize;
        phone.attributedText = AttributedString(@"• 联系方式：", UIFontMake(14), COLOR999, @"156456456", UIFontMake(14), COLOR1515, NSTextAlignmentLeft, 3);
        [backView addSubview:phone];
        
        MyLinearLayout *bottom = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
        bottom.myHorzMargin = 0;
        bottom.myHeight = 40;
        bottom.subviewHSpace = 15;
        bottom.gravity = MyGravity_Horz_Right | MyGravity_Vert_Center;
        [backView addSubview:bottom];
        
        {
            
            UIButton *delete = [UIButton createButtonText:@"删除" font:UIFontMake(14) textColor:COLOR999];
            delete.mySize = CGSizeMake(60, 34);
            ViewCorner(delete, 17);
            ViewBorder(delete, 1, COLOR999);
            [bottom addSubview:delete];
            
            
            UIButton *xiugai = [UIButton createButtonText:@"修改" font:UIFontMake(14) textColor:COLOR999];
            xiugai.mySize = CGSizeMake(60, 34);
            ViewCorner(xiugai, 17);
            ViewBorder(xiugai, 1, COLOR999);
            [bottom addSubview:xiugai];
            
            
            UIButton *saoMiao = [UIButton createButtonText:@"开始扫描" font:UIFontMake(14) textColor:THEME_COLOR];
            saoMiao.mySize = CGSizeMake(88, 34);
            ViewCorner(saoMiao, 17);
            ViewBorder(saoMiao, 1, THEME_COLOR);
            [bottom addSubview:saoMiao];
            
        }
        
    }
    return self;
}


- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority
{
    if (@available(iOS 11.0, *)) {
       return [self.root sizeThatFits:CGSizeMake(targetSize.width - self.safeAreaInsets.left - self.safeAreaInsets.right, targetSize.height)];
    } else {
        return [self.root sizeThatFits:targetSize];
    }
}

@end

#import "TestListViewController.h"
#import "TestSearchViewController.h"
#import "AddUserViewController.h"

@interface TestListViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *tableView;

@end

@implementation TestListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHideNavigationBar = YES;
    self.view.backgroundColor = BACKGROUNDCOLOR;
}

- (void)initSubviews {
    [super initSubviews];
    
    UIImageView *backImage = [[UIImageView alloc]initWithImage:UIImageMake(@"jiance_head")];
    backImage.frame = CGRectMake(0, 0, kScreenWidth, 140);
    [self.view addSubview:backImage];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:UIImageMake(@"icon_arrow_left_white") forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(15, StatusBarHeightConstant, 40, 40);
    backBtn.imageEdgeInsets = UIEdgeInsetsMake(10,10,10,10);
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    root.myHorzMargin = 0;
    root.myTop = 140;
    root.myHeight = 52;
    root.padding = UIEdgeInsetsMake(0, 15, 0, 15);
    root.backgroundColor = COLOR_4;
    root.gravity = MyGravity_Vert_Center | MyGravity_Horz_Center;
    [self.view addSubview:root];
    
    MyLinearLayout *searchBack = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
    searchBack.myHorzMargin = 0;
    searchBack.gravity = MyGravity_Vert_Center | MyGravity_Horz_Center;
    searchBack.myHeight = 36;
    searchBack.backgroundColor = HexColor(@"#F8F8F8");
    ViewCorner(searchBack, 18);
    searchBack.subviewHSpace = 10;
    [root addSubview:searchBack];
    [searchBack setTarget:self action:@selector(searchBackClick)];
    
    {
        UIImageView *search = [[UIImageView alloc]initWithImage:UIImageMake(@"jiance_search")];
        search.mySize = CGSizeMake(16, 16);
        [searchBack addSubview:search];
        
        UILabel *name = [UILabel createLabelText:@"搜索" font:UIFontMake(14) textColor:COLOR999];
        name.mySize = kAutoSize;
        [searchBack addSubview:name];
    }
    
//    [self showEmptyViewWithLoading:NO image:UIImageMake(@"jiance_kong") text:@"您还未添加用户" detailText:@"" buttonTitle:@"" buttonAction:nil];
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 140 + 52, kScreenWidth , kScreenHeight - 192)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = COLOR_5;
    [self.tableView registerClass:[TestTableCell class] forCellReuseIdentifier:@"TestTableCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = false;
    self.tableView.bounces = false;
    [self.view addSubview:self.tableView];
    
    
    // 加号
    UIButton *addBtn = [[UIButton alloc] init];
    [addBtn setImage:UIImageMake(@"jiance_add") forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn];
    [self.view insertSubview:addBtn aboveSubview:self.tableView];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-64);
        make.size.equalTo(@(CGSizeMake(48, 48)));
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TestTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestTableCell" forIndexPath:indexPath];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)addBtnClick {
    AddUserViewController *vc = [AddUserViewController new];
    [self showViewController:vc sender:self];
}

- (void)searchBackClick {
    TestSearchViewController *vc = [TestSearchViewController new];
    [self showViewController:vc sender:self];
}
@end
